﻿using Newtonsoft.Json;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using T.FAS.Runtime.Action.SPI;

namespace T.FAS.Runtime.Action.Engine
{
    public class ActionEngineLocalCache
    {
        private readonly ConcurrentDictionary<string, DataBaseInfo> dataBaseInfoCache;

        private static readonly object syncobj = new object();

        private static ActionEngineLocalCache instance;

        private ActionEngineLocalCache()
        {
            dataBaseInfoCache = new ConcurrentDictionary<string, DataBaseInfo>();
        }

        public static ActionEngineLocalCache GetInstance()
        {
            if (instance == null)
            {
                lock (syncobj)
                {
                    if (instance == null)
                    {
                        instance = new ActionEngineLocalCache();
                    }
                }
            }

            return instance;
        }
        public void AddDataBaseInfoCache(DataBaseInfo info)
        {
            dataBaseInfoCache[info.ID] = info;
        }
        public DataBaseInfo GetDataBaseInfoFromLocalCache(string databaseId)
        {
            if (!dataBaseInfoCache.ContainsKey(databaseId))
            {
                return null;
            }
            return dataBaseInfoCache[databaseId];
        }
    }
}
